#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,list[1005] = {0};
	cin >> n;
	int team,temp,score;
	for(int i = 0;i < n;i++){
		scanf("%d-%d %d",&team,&temp,&score);
		list[team] += score;
	}
	int maxi = 0;
	for(int i = 1;i < 1001;i++){
		if(list[i]>list[maxi]) maxi = i;
	}
	cout << maxi << ' ' << list[maxi];
	
	return 0;
}
